package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ConstructionEncloaure;
import com.ruoyi.system.mapper.ConstructionEncloaureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ConstructionMapper;
import com.ruoyi.system.domain.Construction;
import com.ruoyi.system.service.IConstructionService;

/**
 * 施工Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-06-21
 */
@Service
public class ConstructionServiceImpl implements IConstructionService 
{
    @Autowired
    private ConstructionMapper constructionMapper;
   @Autowired
    private ConstructionEncloaureMapper constructionEncloaureMapper;

    /**
     * 查询施工
     * 
     * @param cId 施工ID
     * @return 施工
     */
    @Override
    public Construction selectConstructionById(Long cId)
    {
        Construction construction = constructionMapper.selectConstructionById(cId);
        ConstructionEncloaure constructionEncloaure = new ConstructionEncloaure();
        constructionEncloaure.setcId(cId);
        construction.setConstructionEncloaureList(constructionEncloaureMapper.selectConstructionEncloaureList(constructionEncloaure));
        return construction;
    }

    /**
     * 查询施工列表
     * 
     * @param construction 施工
     * @return 施工
     */
    @Override
    public List<Construction> selectConstructionList(Construction construction)
    {
        List<Construction> constructions = constructionMapper.selectConstructionList(construction);
        for (int i = 0; i <constructions.size(); i++) {
            ConstructionEncloaure constructionEncloaure = new ConstructionEncloaure();
            constructionEncloaure.setcId(constructions.get(i).getcId());
            constructions.get(i).setConstructionEncloaureList(constructionEncloaureMapper.selectConstructionEncloaureList(constructionEncloaure));
        }
        return constructions;
    }

    /**
     * 新增施工
     * 
     * @param construction 施工
     * @return 结果
     */
    @Override
    public int insertConstruction(Construction construction)
    {construction.setCreateTime(DateUtils.getNowDate());
        return constructionMapper.insertConstruction(construction);
    }

    /**
     * 修改施工
     * 
     * @param construction 施工
     * @return 结果
     */
    @Override
    public int updateConstruction(Construction construction)
    {construction.setUpdateTime(DateUtils.getNowDate());
        return constructionMapper.updateConstruction(construction);
    }

    /**
     * 批量删除施工
     * 
     * @param cIds 需要删除的施工ID
     * @return 结果
     */
    @Override
    public int deleteConstructionByIds(Long[] cIds)
    {
        return constructionMapper.deleteConstructionByIds(cIds);
    }

    /**
     * 删除施工信息
     * 
     * @param cId 施工ID
     * @return 结果
     */
    @Override
    public int deleteConstructionById(Long cId)
    {
        return constructionMapper.deleteConstructionById(cId);
    }
}
